package com.vhans.db.service.impl;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vhans.core.domain.Management;
import com.vhans.core.utils.BeanCopyUtils;
import com.vhans.db.mapper.ManagementMapper;
import com.vhans.db.model.dto.ConditionDTO;
import com.vhans.db.model.dto.management.ManagementDTO;
import com.vhans.db.model.vo.management.ManagementInfoVO;
import com.vhans.db.model.vo.management.ManagementVO;
import com.vhans.db.service.IManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 管理Service业务层处理
 * 
 * @author vhans
 * @date 2023-05-20
 */
@Service
public class ManagementServiceImpl extends ServiceImpl<ManagementMapper, Management> implements IManagementService {
    @Autowired
    private ManagementMapper managementMapper;

    /**
     * 查询管理列表
     * 
     * @param condition 条件
     * @return 管理
     */
    @Override
    public List<ManagementVO> selectManagementVOList(ConditionDTO condition) {
        // 查询管理信息
        return managementMapper.selectManagementVOList(condition);
    }

    /**
     * 新增管理
     * 
     * @param management 管理
     * @return 插入id
     */
    @Override
    public Integer insertManagement(ManagementDTO management) {
        // 要添加的管理
        Management newManagement = BeanCopyUtils.copyBean(management, Management.class);
        managementMapper.insert(newManagement);
        return newManagement.getId();
    }

    /**
     * 获取管理编辑信息
     *
     * @param id 管理主键
     * @return 管理
     */
    @Override
    public ManagementInfoVO selectManagementInfoById(Integer id) {
        // 查询管理信息
        ManagementInfoVO managementInfoVO = managementMapper.selectManagementInfoById(id);
        Assert.notNull(managementInfoVO, "没有该管理");
        // 下面可以扩展信息delete
        return managementInfoVO;
    }

    /**
     * 修改管理
     * 
     * @param management 管理
     * @return 影响行
     */
    @Override
    public int updateManagement(ManagementDTO management) {
        // 要修改的管理
        Management newManagement = BeanCopyUtils.copyBean(management, Management.class);
        return managementMapper.updateById(newManagement);
    }

    /**
     * 批量删除管理
     *
     * @param idList 需要删除的管理主键列表
     * @return 影响行
     */
    @Override
    public int deleteManagementByIdIdList(List<Integer> idList) {
        // 删除管理
        return managementMapper.deleteBatchIds(idList);
    }
}
